#include<sys/un.h>
#include<sys/socket.h>
#include<string.h>
#include<assert.h>
#include<stdio.h>
#include<unistd.h>
#include <stdlib.h>
#define SV_SOCK_PATH "/tmp/us_xfr"

#define BUF_SIZE 1024
#define BACKLOG 5

int main()
{
    struct sockaddr_un addr;
    // 初始化此文件公共文件的路径
    memset(&addr,0,sizeof(struct sockaddr_un));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path,SV_SOCK_PATH,sizeof(addr.sun_path) - 1);
    //打开文件描述符
    int sfd = socket(AF_UNIX,SOCK_STREAM,0);
    assert(sfd != -1);
    // 对等
    assert(connect(sfd,(struct sockaddr *) &addr,sizeof (struct sockaddr_un) ) != -1);

    char buf[BUF_SIZE];

    int numRead = 0;
    // 接受
    while((numRead = read(STDIN_FILENO,buf,BUF_SIZE)) > 0)
        assert(write(sfd,buf,numRead) == numRead) ;
    assert(numRead != -1);
    return 0;
}